﻿using System;
using System.Data.Linq.Mapping;
using System.Runtime.Serialization;
using CoreLibrary.Date;

namespace IBBI.DataBase.Persistent {

    [DataContract]
    [Table(Name = "IBBI_CATEGORY")]
    public class Category {

        public Category () {
            Enable = true;
            DateCreated = DateTime.Now;
            DateUpdated = DateUtil.Epoch;
        }

        /// <summary>
        /// 1
        /// </summary>
        [DataMember]
        [Column(Name = "ID", IsPrimaryKey = true, IsDbGenerated = true)]
        public int Id { get; set; }

        /// <summary>
        /// 2
        /// </summary>
        [DataMember]
        [Column(Name = "NAME")]
        public string Name { get; set; }
        
        /// <summary>
        /// 3
        /// </summary>
        [DataMember]
        [Column(Name = "TITLE")]
        public string Title { get; set; }

        /// <summary>
        /// 4
        /// </summary>
        [DataMember]
        [Column(Name = "TYPE")]
        public int Type { get; set; }

        /// <summary>
        /// 5
        /// </summary>
        [DataMember]
        [Column(Name = "THUMB")]
        public string Thumb { get; set; }

        /// <summary>
        /// 6
        /// </summary>
        [DataMember]
        [Column(Name = "DESCRIPTION")]
        public string Description { get; set; }

        /// <summary>
        /// 7
        /// </summary>
        [DataMember]
        [Column(Name = "KEYWORDS")]
        public string Keywords { get; set; }

        /// <summary>
        /// 8
        /// </summary>
        [DataMember]
        [Column(Name = "ENABLE")]
        public bool Enable { get; set; }

        /// <summary>
        /// 9
        /// </summary>
        [DataMember]
        [Column(Name = "PID")]
        public int? PID { get; set; }

        /// <summary>
        /// 10
        /// </summary>
        [DataMember]
        [Column(Name = "LID")]
        public int LID { get; set; }

        /// <summary>
        /// 11
        /// </summary>
        [DataMember]
        [Column(Name = "RID")]
        public int RID { get; set; }

        /// <summary>
        /// 12
        /// </summary>
        [DataMember]
        [Column(Name = "LEVEL")]
        public int Level { get; set; }

        /// <summary>
        /// 13
        /// </summary>
        [DataMember]
        [Column(Name = "LIST_ORDER")]
        public int ListOrder { get; set; }
        
        /// <summary>
        /// 14
        /// </summary>
        [DataMember]
        [Column(Name = "DATE_CREATED")]
        public DateTime DateCreated { get; set; }

        /// <summary>
        /// 15
        /// </summary>
        [DataMember]
        [Column(Name = "DATE_UPDATED")]
        public DateTime DateUpdated { get; set; }
        
        public bool IsRoot {
            get {
                return PID == null;
            }
        }

        public bool IsLeaf {
            get {
                return RID == LID + 1;
            }
        }

    }

}